-- Rejestr flag
-- Wejscie danych: FLAGSIN(3..0)
-- Wyjscie danych: FLAGSOUT(3..0)
-- Wejscia sterujace:
-- IE# (input enable)
-- OE# (output enable)
-- Flagi:
-- ZF CF SF OVF
-- 3  2  1  0

library IEEE;
use IEEE.Std_Logic_1164.all;
use IEEE.Std_Logic_Arith.all;

entity FLAGS is
  generic (delay : time := 5 ns);
  port (IE, OE   : in std_logic;
        FLAGSIN  : in std_logic_vector(3 downto 0);
        FLAGSOUT : out std_logic_vector(3 downto 0));
end entity FLAGS;

architecture FLAGS_arch of FLAGS is
begin
  process(IE, OE, FLAGSIN)
    variable buf : std_logic_vector(3 downto 0) := "0000";
    begin
      if (IE = '0') then
        buf := FLAGSIN;
      end if;
      if (OE = '0') then FLAGSOUT <= buf after delay;
      else FLAGSOUT <= "ZZZZ" after delay;
      end if;
    end process;
end architecture FLAGS_arch;
